package com.sky.controller.admin;

import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.entity.Orders;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrdersService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
@Api(tags = "订单管理接口")
@RequestMapping("/admin/order")
public class OrderController {
    @Autowired
    private OrdersService ordersService;


    /**
     * 订单搜索
     * @param dto
     * @return
     */
    @ApiOperation("订单搜索")
    @GetMapping("/conditionSearch")
    public Result<PageResult> conditionSearch(OrdersPageQueryDTO dto){
        //订单搜索是条件分页查询
        log.info("订单搜索:{}",dto);
        PageResult pageResult = ordersService.conditionSearch(dto);

        return Result.success(pageResult);
    }


    //接单
    @ApiOperation("接单")
    @PutMapping("/confirm")
    public Result<String> newlyIncreased(@RequestBody Orders orders1){
        log.info("接单:{}",orders1);
        ordersService.newlyIncreased(orders1);
        return Result.success();
    }

    //拒单
    @ApiOperation("拒单")
    @PutMapping("/rejection")
    public Result<String> shareTheBill(@RequestBody OrdersRejectionDTO ordersRejectionDTO){
        log.info("拒单:{}",ordersRejectionDTO);
        ordersService.shareTheBill(ordersRejectionDTO);
        return Result.success();
    }

    /**
     * 查询订单详情
     * @param id
     * @return
     */
    @ApiOperation("查询订单详情")
    @GetMapping("/details/{id}")
    public Result<OrderVO> getByOrderId(@PathVariable Long id){
        log.info("查询订单详情:{}",id);
        OrderVO orderVO = ordersService.getById(id);
        return Result.success(orderVO);
    }


    /**
     * 各个状态的订单数量统计
     * @return
     */
    @ApiOperation("各个状态的订单数量统计")
    @GetMapping("/statistics")
    public Result<OrderStatisticsVO> statistics(){
        log.info("各个状态的订单数量统计");
        OrderStatisticsVO vo = ordersService.statistics();
        return Result.success(vo);
    }

    /**
     * 订单取消
     * @param ordersCancelDTO
     * @return
     */
    @ApiOperation( "订单取消")
    @PutMapping("/cancel")
    public Result<String> cancelOrders(@RequestBody OrdersCancelDTO ordersCancelDTO) {
        log.info("订单取消{}",ordersCancelDTO);
        ordersService.cancelOrders(ordersCancelDTO);
        return Result.success();
    }

    /**
     * 订单派送
     * @param id
     * @return
     */
    @ApiOperation("订单派送")
    @PutMapping("/delivery/{id}")
    public Result<String> deliveryOrders(@PathVariable Long id) {
        log.info("订单派送{}",id);
        ordersService.delivery(id);
        return Result.success();
    }

    /**
     * 订单完成
     * @param id
     * @return
     */
    @ApiOperation("订单完成")
    @PutMapping("/complete/{id}")
    public Result<String> completeOrders(@PathVariable Long id) {
        log.info("订单完成{}",id);
        ordersService.complete(id);
        return Result.success();
    }
}
